#!/bin/bash
# 本脚本仅供学习
# hi@tajubao.com
#yum install -y wget && wget -O max.sh http://www.tajubao.com/diy/max.sh && sh max.sh
#特别本地化
#

echo "正在加载库"
######################################################################################## ##########储存库
#
download=http://www.tajubao.com/
#
server_cpu_model_name_shell=$(cat /proc/cpuinfo | grep "model name" |uniq) #获取cpu型号名字
server_cpu_model_name=${server_cpu_model_name_shell:13:99} #截取CPU版号具体型号名字
#
server_cpu_cpu=$(grep 'physical id' /proc/cpuinfo |sort |uniq |wc -l) #获取CPU物理数量
#
server_free_kb=$(free | awk '/Mem/ {print $2}') #获取服务器内存大小，单位kb
server_free_mb=`expr $server_free_kb / 1024 ` #内存换算kb -> mb 
server_free_gb=`awk -v x=$server_free_mb -v y=1024 'BEGIN{printf "%.2f\n",x/y}'` #内存换算 mb -> gb 
#
server_dev_free_kb=$(df -k ./ | awk '{print int($2)}' | tail -n 1) #获取硬盘容量 kb 
server_dev_free_gb=`awk -v x=$server_dev_free_kb -v y=1024 'BEGIN{printf "%.2f\n",x/y/y}'` #换孙硬盘容量kb -》 gb
#
server_lan_ip=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}' ) #获取内网IP
server_wan_ip="$(curl 'ifconfig.io/ip')" #获取公网IP
#
server_cpu_cpu_mhz_shell=$(cat /proc/cpuinfo | grep "cpu MHz" | uniq) #获取cpu频率
server_cpu_mhz_a="${server_cpu_cpu_mhz_shell:11:99}"
server_cpu_mhz_b="${server_cpu_cpu_mhz_shell:11:99}"
server_cpu_mhz=`awk -v x=$server_cpu_mhz_a -v y=0.$server_cpu_mhz_b 'BEGIN{printf "%.0f\n",x-y}'` #运行包含小数点的计算
#
#
server_ip_line_shell="$(curl http://myip.ipip.net | awk '{print $6}' )" #获取ip线路
server_ip_gps_country_shell="$(curl http://myip.ipip.net | awk '{print $3}' )" #获取ip地区 为截取前 国家
server_ip_gps_country="${server_ip_gps_country_shell:4}" #截取后 国家
server_ip_gps_province="$(curl http://myip.ipip.net | awk '{print $4}' )" #获取ip地区 省
server_ip_gps_city="$(curl http://myip.ipip.net | awk '{print $5}' )"  #获取ip地区 市
#
server_load_5min="$(cat /proc/loadavg | cut -d ' ' -f 1-3 | awk '{print $1}')" #服务器5分钟的负载
server_load_10min="$(cat /proc/loadavg | cut -d ' ' -f 1-3 | awk '{print $2}')" #服务器10分钟的负载
server_load_15min="$(cat /proc/loadavg | cut -d ' ' -f 1-3 | awk '{print $3}')" #服务器15分钟的负载
#
server_disk_number="$(fdisk -l |grep 'Disk' |grep -v 'VolGroup' |awk -F , '{print $1}' | sed 's/Disk identifier.*//g' | sed '/^$/d'|wc -l)"
#获取硬盘数量
#
server_disk_info="$(fdisk -l |grep 'Disk' |grep -v 'VolGroup' |awk -F , '{print $1}' | sed 's/Disk identifier.*//g' |sed 's/Disk //g' | sed '/^$/d')"
#获取硬盘信息
server_disk_free="$(server_disk_info | grep '80')"
# 
##################################################################################################储存库
##################################################################################################运算库
cd /
cd /usr/bin
if [ ! -e 'wd' ];then
echo "文件不存在"
wget -O max.sh $download/diy/max.sh #下载脚本文件
dos2unix max.sh
chmod 755 max.sh
mv max.sh wd
fi
cd /
cd /root


##################################################################################################运算库
while true
do
while [ "$home" != "0" ] && [ "$home" != "1" ] && [ "$home" != "2" ] && [ "$home" != "3" ] && [ "$home" != "4" ] && [ "$home" != "5" ] && [ "$home" != "6" ] && [ "$home" != "7" ] && [ "$home" != "8" ] && [ "$home" != "9" ] && [ "$home" != "10" ] && [ "$home" != "11" ] && [ "$home" != "12" ]
do
home="1"
echo -e "已回到菜单。"
done
case $home in
    0)
echo -e "已退出脚本"
exit
        ;;
    1)
echo -e "==============菜单如下=============="
echo -e "(0) 退出脚本 | " 
echo -e "(1) 主页菜单 | "
echo -e "(2) 综合信息 | "
echo -e "(3) CPU信息  | "
echo -e "(4) 硬盘信息 | "
echo -e "(5) 变量状态 | "
echo -e "(6) 帮助中心 | "
echo -e "(7) 更新脚本 | "
echo -e "(8) 暂无信息 | "
echo -e "(9) 暂无信息 | "
echo -e "(10) 实用工具 | "
echo -e "(11) 暂无信息 | "
echo -e "(12) 暂无信息 | "
read -p "请回复相应数字: " home; 
        ;;
    2)
echo "================================================================"
echo -e " II  CPU x$server_cpu_cpu  II   \033[32m $server_cpu_model_name\033[0m" 
echo "================================================================"
echo -e " II  配置 II        \033[32m $(nproc) \033[0mH\033[32m $server_free_gb \033[0mGB\033[32m $server_dev_free_gb $server_disk_free \033[0mG"
echo "================================================================"
echo -e " II  IP II          \033[32m$server_lan_ip\033[0m/\033[32m$server_wan_ip\033[0m"
echo "================================================================"
echo " II 地区 && 线路 II  $server_ip_gps_country  $server_ip_gps_province  $server_ip_gps_city  $server_ip_line_shell"
echo "================================================================"
echo " "
read -p "前往菜单：（0）" home;
        ;;
    3)
echo -e "\033[32m==================================================================================\033[0m"
#
echo -e "\033[32m==                          ///===================================================\033[0m"
#
echo -e "\033[32m==    =====================///    $server_cpu_model_name\033[0m"
#
echo -e "\033[32m==    =====\033[0m\033[47m\033[37m########\033[0m\033[0m\033[32m=======///=====================================================\033[0m"
#
echo -e "\033[32m==    =====\033[0m\033[47m\033[37m########\033[0m\033[0m\033[32m======///====\033[0mCPU x$server_cpu_cpu\033[32m=====\033[0m\033[33m Core X$(nproc) \033[0m\033[32m=========\033[0m\033[31m $server_cpu_mhz Mhz\033[0m\033[32m============\033[0m"
#
echo -e "\033[32m==    =====\033[0m\033[47m\033[37m########\033[0m\033[0m\033[32m=====///=======================================================\033[0m"
#
echo -e "\033[32m==    =================///       \033[37m 反馈邮箱：hi@tajubao.com \033[0m"
#
echo -e "\033[32m==                    ///=========================================================\033[0m"
#
echo -e "\033[32m==================================================================================\033[0m"
echo " "
read -p "前往菜单：（0）" home;
         ;;
    4)
echo -e "\033[44m\033[34m==============================================================================================\033[0m\033[0m"
echo -e "\033[44m——————————————————————————————————————————————————————————————————————————————————————————————\033[0m"
echo -e "\033[44m   ______________________________                                                             \033[0m"
echo -e "\033[44m  |/      ___________________   \|                                                            \033[0m"
echo -e "\033[44m  | 0 ___/                   \ 0 |                                                            \033[0m"
echo -e "\033[44m  |  /                        \  |              硬盘数量 X$server_disk_number                                   \033[0m"
echo -e "\033[44m  | |                          | |                                                            \033[0m"
echo -e "\033[44m  | |                          | |                                                            \033[0m"
echo -e "\033[44m  | |                          | |                                                            \033[0m"
echo -e "\033[44m  | |                          | |                                                            \033[0m"
echo -e "\033[44m  | |                          | |                                                            \033[0m"
echo -e "\033[44m  | |                          | |                                                            \033[0m"
echo -e "\033[44m  | |                          | |                                                            \033[0m"
echo -e "\033[44m  | |                          | |                                                            \033[0m"
echo -e "\033[44m  | |                          | |                                                            \033[0m"
echo -e "\033[44m  | |                          | |                                                            \033[0m"
echo -e "\033[44m  |  \                     ___/  |                                                            \033[0m"
echo -e "\033[44m  | 0 \___________________/    0 |                                                            \033[0m"
echo -e "\033[44m  |\____________________________/|                                                            \033[0m"
echo -e "\033[44m——————————————————————————————————————————————————————————————————————————————————————————————\033[0m"
echo -e "\033[44m\033[34m==============================================================================================\033[0m\033[0m"
read -p "前往菜单：（0）" home;
         ;;
      5)
echo -e "处理器型号（截取前）：$server_cpu_model_name_shell"
echo -e "处理器型号（截取后）：$server_cpu_model_name"
echo -e "物理CPU数量：$server_cpu_cpu"
echo -e "服务器内存容量：$server_free_kb/KB"
echo -e "服务器内存容量：$server_free_mb/MB"
echo -e "服务器内存容量：$server_free_gb/GB"
echo -e "硬盘储存容量：$server_dev_free_kb/KB"
echo -e "硬盘储存容量：$server_dev_free_gb/GB"
echo -e "内网IP：$server_lan_ip"
echo -e "外网IP：$server_wan_ip"
echo -e "服务器线路(联通、电信、移动)：$server_ip_line_shell"
echo -e "服务器地区(国家：未截取)：$server_ip_gps_country_shell"
echo -e "服务器地区(国家)：$server_ip_gps_country"
echo -e "服务器地区(省)：$server_ip_gps_province"
echo -e "服务器地区(市)：$server_ip_gps_city"
echo -e "服务器5分钟的负载百分比：$server_load_5min%"
echo -e "服务器10分钟的负载百分比：$server_load_10min%"
echo -e "服务器15分钟的负载百分比：$server_load_15min%"
echo -e "$bug_openssh_openssl"

read -p "前往菜单：（0）" home;
         ;;
      6)
echo -e "\033[42m\033[32m++++++++++++++++++++\033[0m\033[0m帮助中心\033[42m\033[32m++++++++++++++++++++\033[0m\033[0m"
echo -e "1.如果获取外网IP的链接失效，请自建一个PHP页面，"
echo -e "内容如下填进去放在另一台服务器或主机上,最后把链接替换成你自建网页的链接即可。 "
echo -e '                                                                              '
echo -e '<?php                                                                         '
echo -e 'echo $_SERVER['REMOTE_ADDR'];                                                 '
echo -e '?>                                                                            '
echo -e "\033[42m\033[32m++++++++++++++++++++\033[0m\033[0m\033[31m我有底线\033[0m\033[42m\033[32m++++++++++++++++++++\033[0m\033[0m"
read -p "前往菜单：（0）" home;
         ;;
      7)
cd /
cd /usr/bin
echo "正在更新中"
wget -O max.sh $download/diy/max.sh #下载脚本文件
dos2unix max.sh #转换为linux可读类型
chmod 755 max.sh #赋予755权限
mv max.sh wd #更改文件名
cd /
cd /root
echo -e "已更新完成,请输入 \033[32mwd\033[0m 启动。"
exit
         ;;
      8)
echo -e "暂无信息"
read -p "前往菜单：（0）" home;
         ;;
      9)
echo -e "暂无信息"
read -p "前往菜单：（0）" home;
         ;;
      10) #10//工具子页面-开始
    while [ "$home" == "10" ]
    do
    home="X" #主页菜单暂停中
    tool="1" #启动工具列表菜单
    done

        while [ "$tool" != "out" ]
        do
              case $tool in
              0)
              echo -e "已退出工具"
              tool="out"
              home=1
                      ;;
              1)
              echo -e "工具列表"
              echo -e "工具列表"
              read -p "前往菜单：（0）" tool;
                      ;;
              2)
              echo -e "工具具体2"
              read -p "前往菜单：（0）" tool;
                      ;;
              3)
              echo -e "工具具体3"
              read -p "前往菜单：（0）" tool;
                      ;;
              4)
              echo -e "工具具体4"
              read -p "前往菜单：（0）" tool;
                      ;;
              5)
              echo -e "工具具体5"
              read -p "前往菜单：（0）" tool;
                      ;;
              esac
                  if [ "$tool" != "out" ] && [ "$tool" != "0" ] && [ "$tool" != "1" ] && [ "$tool" != "2" ] && [ "$tool" != "3" ] && [ "$tool" != "4" ] && [ "$tool" != "5" ];then
                  tool="1"
                  fi
        done
 #10//工具子页面-结束
         ;;
      11)
echo -e "暂无信息"
read -p "前往菜单：（0）" home;
         ;;
      12)
echo -e "暂无信息"
read -p "前往菜单：（0）" home;
         ;;
esac
done